using System.Linq;
using System.Collections;
using System.Collections.Generic;

namespace Ayatta.Common.Extension
{
    public static class CollectionExtension
    {

        public static bool IsNullOrEmpty<T>(this ICollection<T> target)
        {
            return (target == null) || (target.Count == 0);
        }

        public static bool IsNullOrEmpty(this IEnumerable target)
        {
            if (target != null)
            {
                return !target.GetEnumerator().MoveNext();
            }
            return true;
        }

        /// <summary>
        /// Determines whether a collection is null or has no elements without having to enumerate the entire collection to get a count.  Uses LINQ.
        /// </summary>
        /// <typeparam name="T">The item type.</typeparam>
        /// <param name="target">The items.</param>
        /// <returns>
        /// <c>true</c> if the collection is null or has no elements; otherwise, <c>false</c>.
        /// </returns>
        public static bool IsNullOrEmpty<T>(this IEnumerable<T> target)
        {
            return target == null || !target.Any();
        }
    }
}